from django.conf import settings
from .base import Base
import json

class DownDeploy(Base):
    def __init__(self, data):
        super(DownDeploy, self).__init__(data)
        self.wait_num = 20*60

    def struct_msg(self):
        url = "".join([settings.DOWNURL, "?file_path=", self.path])
        msg = {"TID": self.tid,
               "TYPE": 1,
               "PATH": url,
               "MD5": self.md5
               }
        msg = json.dumps(msg)
        return msg

    def struct_pub_topic(self):
        notify = "transfer"
        gid = "".join(["/", self.gateway_id, "/"])
        func = "download"
        topic = "".join([notify, gid, func])
        return topic


    def struct_sub_topic(self):
        notify = "transfered"
        gid = "".join(["/", self.gateway_id, "/"])
        func = "download"
        topic = "".join([notify, gid, func])
        return topic
